fix: clamp convert_size_bytes_to_string at largest unit (#184)#185
Open
patchwright wants to merge 1 commit into
Open
fix: clamp convert_size_bytes_to_string at largest unit (#184)#185patchwright wants to merge 1 commit into
patchwright wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #185 +/- ##
=======================================
Coverage 98.33% 98.33%
=======================================
Files 13 13
Lines 780 780
=======================================
Hits 767 767
Misses 13 13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
Fixes #184.
convert_size_bytes_to_string()raisesIndexErrorfor any size of 1024 YB or more (2**90 bytes and up). Confirmed on main HEAD c98dbf6.Root cause: the unit-selection loop guard is
factor <= factor_limit. Whenfactorreaches the last index (YB) and the value is still >= 1024, the loop runs once more and incrementsfactorpast the end ofSIZE_UNITS, sounits[factor]is out of range.Fix: change the guard to
factor < factor_limitso the loop stops at the largest unit and the size saturates in YB. One line changed. Sizes below 2**90 are unaffected (byte-identical output).Related issue
#184
How to test
Before this PR:
After this PR:
Added a parametrized regression test (280, 290, 2**100). Full converter suite: 32 passed.
Backward compatibility
No breaking changes. Only inputs that previously raised IndexError change behavior.
Checklist before requesting a review
Assisted-by: Claude (code generation, reviewed and tested locally)